/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package shared;

/**
 *
 * @author LMahassine
 */
/* Imports the java.io package class. */
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.Serializable;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;


@SuppressWarnings("serial")
public class FileInfo implements Serializable {
	/* Declares the objects of String class. */
	byte[] md5Hash;
	String fileName;
        Long fileSize;


   
    private void generateHash(File file) throws NoSuchAlgorithmException, FileNotFoundException
    {
       MessageDigest digest = MessageDigest.getInstance("MD5");
       FileInputStream fs = new FileInputStream(file);

       DigestInputStream di = new DigestInputStream(fs, digest);
       md5Hash = di.getMessageDigest().digest();

    }
    public byte[] getMd5Hash() {
        return md5Hash;
    }

    public void setMd5Hash(byte[] hash) {
        this.md5Hash = hash;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public Long getFileSize() {
        return fileSize;
    }

    public void setFileSize(Long fileSize) {
        this.fileSize = fileSize;
    }
	

	/* Defines default constructors. */
	public FileInfo(File file) throws NoSuchAlgorithmException, FileNotFoundException {
		generateHash(file);
		this.fileName = file.getName();
		this.fileSize = file.length();
                
	}
}
